#include <network.h>
using namespace engine;

NetworkServer* g_server;

class MyServerListener : public NetworkServerListener
{
public:
	virtual void onConnected(void* net)
	{
		printf("client connected %p \n", net);
	}

	virtual void onDisconnected(void* net)
	{
		printf("client disconnected %p \n", net);
	}
	
	virtual void onMessage(void *net, NetworkStream& stream)
	{
		g_server->sendStream(stream, net);
	}
};

MyServerListener* g_listener;

int main()
{
	WSADATA wsaData;
	WSAStartup(MAKEWORD(2, 2), &wsaData);

	g_listener = new MyServerListener();

	g_server = new NetworkServer();
	g_server->addListener(g_listener);

	g_server->start(NULL, 18000, 3000);

	uint32 t = timeGetTime();

	while (true)
	{
		if (timeGetTime() - t < 1)
		{
			Sleep(1);
		}
		else
		{
			t = timeGetTime();

			g_server->handleMessages();
		}
	}
}